﻿using UnityEngine;
using System.Collections;
using UnityEditor;

[CustomEditor(typeof(EnemyManager))]
public class EnemyEditor : Editor {

    private SerializedObject enemySerialized;
    private EnemyManager myEnemy;

    void OnEnable()
    {
        enemySerialized = new SerializedObject(target);
        myEnemy = (EnemyManager)target;
    }

    public override void OnInspectorGUI()
    {
        EnemyManager enemy = target as EnemyManager;

        if (GUILayout.Button("Add Patrol Point"))
        {
            enemy.AddPatrolPosition(enemy.transform.position);
            EditorUtility.SetDirty(target);
            EditorUtility.SetDirty(myEnemy);
        }

        if (GUILayout.Button("Advance Patrol Point"))
        {
            enemy.NextPatrolPoint();
        }

        if (GUILayout.Button("Remove Current Patrol Point"))
        {
            enemy.RemoveCurrentPatrolPoint();
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
            EditorUtility.SetDirty(myEnemy);
        }

        enemySerialized.ApplyModifiedProperties();

        DrawDefaultInspector();

    }
}
